package com.ibm.cps.forwarder;

import java.lang.Thread.UncaughtExceptionHandler;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.google.common.base.Throwables;
import com.ibm.util.LocalConfig;
import com.ibm.util.exception.CPSException;

public class RuntimeExceptionHandler implements UncaughtExceptionHandler {

	private Logger logger = Logger.getLogger(RuntimeExceptionHandler.class);

	@Override
	public void uncaughtException(Thread t, Throwable e) {
		try {
			PropertyConfigurator.configure(LocalConfig.getLoggerProperties());
		} catch (CPSException e1) {
			e1.printStackTrace();
		}
		logger.error("From thread " + t.getName() + ": "
				+ Throwables.getStackTraceAsString(e));
	}

}
